import 'package:util/result/result.dart';

Result<T> runCatching<T>(T Function() block) {
  try {
    return Result.ok(block());
  } catch (e) {
    return Result.error(Exception(e.toString()));
  }
}

Future<Result<T>> runCatchingAsync<T>(Future<T> Function() block) async {
  try {
    final result = await block();
    return Result.ok(result);
  } catch (e) {
    return Result.error(Exception(e.toString()));
  }
}
